/*
 * @Author: szx
 * @Date: 2021-12-13 12:26:50
 * @LastEditTime: 2021-12-13 12:40:29
 * @Description:
 * @FilePath: \leetcode\800-899\807\807.js
 */
/*
 * @Author: szx
 * @Date: 2021-12-13 12:26:50
 * @LastEditTime: 2021-12-13 12:26:59
 * @Description:
 * @FilePath: \leetcode\800-899\807\807.js
 */
/**
 * @param {number[][]} grid
 * @return {number}
 */
var maxIncreaseKeepingSkyline = function (grid) {
    const m = grid.length;
    const arrm = new Array(m).fill(0);
    const arrn = new Array(m).fill(0);
    for (let i = 0; i < m; i++) {
        for (let j = 0; j < m; j++) {
            arrm[i] = Math.max(arrm[i], grid[i][j]);
            arrn[i] = Math.max(arrn[i], grid[j][i]);
        }
    }
    let sum = 0;
    for (let i = 0; i < m; i++) {
        for (let j = 0; j < m; j++) {
            console.log(grid[i][j]);
            sum += Math.min(arrm[i], arrn[j]) - grid[i][j];
        }
    }
    return sum;
};
console.log(
    maxIncreaseKeepingSkyline([
        [3, 0, 8, 4],
        [2, 4, 5, 7],
        [9, 2, 6, 3],
        [0, 3, 1, 0]
    ])
);
